/**
 * 手机号加密显示
 * @param {*} mobile
 */
export const encryptMobile = mobile => {
    if (mobile) {
      return mobile.substr(0, 3) + "****" + mobile.substr(7);
    } else {
      return "";
    }
  };
  /**
 * 证件号加密显示
 * @param {*} mobile
 */
export const encryptidCard = cardNum => {
    if (cardNum) {
      let newStr = ''
      newStr = cardNum.substring(0, cardNum.length - 4) + '***' + cardNum.substring(cardNum.length - 1)
      return newStr
    } else {
      return ''
    }
  };
  
export const formatrecive = val => {
    let date = new Date(val.replace(/-/g,'/')).getTime();
    let time = date + 5184000000;
    let newTime = new Date(time);
    return newTime.getFullYear().toString() + '年' + (newTime.getMonth() + 1).toString() + '月' + newTime.getDate().toString() + '日';
    // return val.split('-')[0] + '年' + val.split('-')[1] + '月' + val.split('-')[2] + '日'
  }
  /**
   * 日期格式化
   * @param {传入的时间值} val
   * @param {格式化的类型} format
   */
  export const formatTime = (val, format) => {
    if (!val) return "";
    let newDate = new Date(val.replace(new RegExp(/-/gm), "/"));
    // let year = newDate.getFullYear().toString(),
    //   month = newDate.getMonth() + 1 < 10 ? "0" + (newDate.getMonth() + 1) : (newDate.getMonth() + 1),
    //   date = newDate.getDate() < 10 ?  "0" + newDate.getDate() : newDate.getDate(),
    //   hour = newDate.getHours() < 10 ? "0" + newDate.getHours() : newDate.getHours(),
    //   minute = newDate.getMinutes() < 10 ? "0" + newDate.getMinutes() : newDate.getMinutes(),
    //   second = newDate.getSeconds() < 10 ? "0" + newDate.getSeconds() : newDate.getSeconds();
    let year = newDate.getFullYear().toString(),
      month = "0" + (newDate.getMonth() + 1),
      date = "0" + newDate.getDate(),
      hour = "0" + newDate.getHours(),
      minute = "0" + newDate.getMinutes(),
      second = "0" + newDate.getSeconds();
    switch (format) {
      case "YYYYMMDD":
        return (
          year +
          month.substring(month.length - 2, month.length) +
          date.substring(date.length - 2, date.length)
        );
        break;
      case "YYMMDD":
        return (
          year.substring(2) +
          month.substring(month.length - 2, month.length) +
          date.substring(date.length - 2, date.length)
        );
        break;
      case "HH:MM":
        return (
          hour.substring(hour.length - 2, hour.length) +
          ":" +
          minute.substring(minute.length - 2, minute.length)
        );
        break;
      case "CN":
        return (
          month.substring(month.length - 2, month.length) +
          "月" +
          date.substring(date.length - 2, date.length) + "日"
        );
        break;
      default:
        return (
          year +
          "-" +
          month.substring(month.length - 2, month.length) +
          "-" +
          date.substring(date.length - 2, date.length)
        );
        break;
    }
  };
  /**
 * 验证手机号码
 * @param {传入手机号码} mobile
 */
export const regMobile = mobile => {
    // debugger;
    // let reg = /^(13[0-9]|14[5-9]|15[012356789]|16[5-6]|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
    let reg = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
    if (reg.test(mobile)) {
      return true;
    } else {
      return false;
    }
  };
  /**
 * 验证英文
 * @param {传入字符串} val
 */
export const regEn = val => {
    let reg = /^[a-zA-Z]*$/;
    if (reg.test(val)) {
      return true;
    } else {
      return false;
    }
  };
  /**
   * 验证中文
   * @param {传入字符串} val
   */
  export const regCn = val => {
    let reg = /^[\u4e00-\u9fa5]*$/;
    if (reg.test(val)) {
      return true;
    } else {
      return false;
    }
  };
  /**
 * 判断运行环境
 */
export const browser = () => {
    let ua = navigator.userAgent.toLocaleLowerCase();
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
      // 微信打开
      return 'JSAPI';
    } else {
      return 'MWEB';
    }
  }
  /**
 * 正则校验 <>
 */
export const RegExps = it => {
    // debugger
    let patrn = /[`~$%^*\+<>"'\[\]·~￥%……*——\+《》【】]/im;
    if (!patrn.test(it)) {
      // 包含特殊字符
      return false;
    } else {
      // 不包含特殊字符
      return true;
    }
  }
 
